import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'enums/index.dart';
import 'nexgo_platform_interface.dart';

/// An implementation of [PrinterPlatform] that uses method channels.
class MethodChannelPrinter extends NexgoPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final method = const MethodChannel('printer');
  @override
  Future<bool> init() async {
    var result = await method.invokeMethod('PRINT_INIT');
    return result;
  }

  @override
  Future<bool> printText({
    required String text,
    NexgoAlignEnum align = NexgoAlignEnum.left,
  }) async {
    var result = await method.invokeMethod('PRINT_TEXT', {
      'text': text,
      'align': align.value,
    });
    return result;
  }

  @override
  Future<bool> feed({
    required int val,
  }) async {
    var result = await method.invokeMethod('PRINT_FEED', {
      'feed': val,
    });
    return result;
  }

  @override
  Future<bool> printImage({
    required Uint8List image,
    NexgoAlignEnum align = NexgoAlignEnum.left,
  }) async {
    var result = await method.invokeMethod('PRINT_BMP', {
      'image': image,
      'align': align.value,
    });
    return result;
  }

  @override
  Future<bool> setLED({
    required NexgoLightModeEnum light,
    bool enbeld = true,
  }) async {
    var result = await method.invokeMethod('PRINT_LED', {
      'light': light.value,
      'enabled': enbeld,
    });
    return result;
  }
}
